package checking;

import java.util.ArrayList;
import java.util.StringTokenizer;

import model.Project;

public class InputValidation {
	
	public void validateResponse(int response, int numberOfChoice) {

		   if(response<1 || response > numberOfChoice){
		       throw new IllegalArgumentException(
		        "Your choice is not valid");
		       
		   }
		}
	
	public void validateString(String name){
		
		if(name.equals(" ")){
			throw new NullPointerException(
					"You should enter a valid name!");
		}
		
	}
	
	public void validateStringForProjectName(String name, ArrayList<Project> projectList){
		
		for(int i=0; i<projectList.size(); i++){
			if(name.equals(projectList.get(i).getName())){
				throw new IllegalArgumentException(
						"Your value " + name + "is already exist in the project list.Please enter another name!");
			}
		}
		
	}

	
	public int checkInteger(String oString){
		int response=0;
		try {
			response = Integer.parseInt(oString);
			
		} catch (Exception e) {
			System.out.println("Invalid Entry!");
		}
		return response;
		
	}
	
	
	public boolean date_control(String date) 
	{ 
	 
	int uzunluk = date.length(); 
	if (uzunluk > 10 || uzunluk < 8) 
	return false; 
	StringTokenizer st = new StringTokenizer(date, "-");
	
		String token1 = st.nextToken();
		String token2 = st.nextToken();
		//String token3 = st.nextToken();
		
		int gun=Integer.parseInt(token1);
		int ay=Integer.parseInt(token2);
		if(gun<1 || gun>31) return false;		
		if(ay<1 || ay>12)return false;
		else return true;
		//int yil=Integer.parseInt(token3);
		 
	}

}
